package enumerable;

import java.util.Map.Entry;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/*
		 * Data initialization for testing purposes
		 */
		String[] data = {"One",
				"Two",
				"Three",
				"Four",
				"Five",
				"Six",
				"Seven",
				"Eight",
				"Nine",
				"Ten",
				"Eleven",
				"Twelve",
				"Thirteen",
				"Fourteen",
				"Fifteen"};
		
		LinkedList<String> test = new LinkedList<String>();
		for (String s : data) {
			test.add(s);
		}

		/*
		 * Selection tests
		 */
		Enumerable<String> selection = test.select(new Selector<String>() {
			@Override
			public boolean predicate(String elem) {
				return elem.length() == 4;
			}			
		});
		
		
		selection.forEach(new Mapper<String>() {
			public void map(String elem) {
				System.out.println(elem);
			}
		});
		
		/*
		for (String s : selection) {
			System.out.println(s);
		}
		*/
		System.out.println("===========================");
		
		/*
		 * Projection tests
		 */
		Enumerable<Integer> projection = test.project(new Projector<String, Integer>() {
			public Integer project(String s) {
				return s.length();
			}
		});

		for (Integer i : projection) {
			System.out.println(i);
		}
		
		System.out.println("===========================");
		
		/*
		 * Count tests
		 */
		System.out.println(test.count());
		
		System.out.println(test.count(new Selector<String>() {
			public boolean predicate(String s) {
				return s.length() == 4;
			}
		}));
		
		System.out.println("===========================");
		
		/*
		 * Map testing
		 */
		HashMap<Integer, String> map = new HashMap<Integer, String>();
		for (int i = 0; i < data.length; ++i) {
			map.put(i, data[i]);
			System.out.println(data[i]);
		}
		
		for (Entry<Integer, String> i : map) {
			System.out.println(i.getKey() + " - " + i.getValue());
		}
		
		System.out.println("===========================");
		
		Enumerable<Entry<Integer, String>> list = map.select(new Selector<Entry<Integer, String>>() {
			public boolean predicate(Entry<Integer, String> e) {
				return e.getValue().length() == 4;
			}
		});
		
		for (Entry<Integer, String> e : list) {
			System.out.println(e.getKey() + " - " + e.getValue());
		}
		
		System.out.println("===========================");
	}
}
